package util

import (
	"bytes"
	"database/sql"
	"fmt"
	"regexp"
	"strconv"
	"strings"

	"gopkg.in/couchbaselabs/gocb.v1"

	"common/goredis"
	"common/logging"
)

type GatewayHouseInfo struct {
	HouseId      uint64
	MasterUserId int64
	Mobile       string
}

var (
	Redis_handle          *goredis.Redis
	Db_zone               *sql.DB
	Db_msmart             *sql.DB
	Db_b2b                *sql.DB
	Appliance_base_bucket *gocb.Bucket
)

const (
	appliance_base_info_prefix = "appliance_base_id_"
)

func InitRedis(redisurl string) {
	var err error
	Redis_handle, err = goredis.DialURL(redisurl)
	if err != nil {
		logging.Error("redis init fail:%s,%s", redisurl, err.Error())
		panic("InitRedis failed")
		return
	} else {
		logging.Info("redis conn ok:%s", redisurl)
	}

}

func InitMysql(mysqlurl string) {
	Db_zone = initMysql(mysqlurl)
}

func InitMysql_Msmart(mysqlurl string) {
	Db_msmart = initMysql(mysqlurl)
}

func InitMysql_B2B(mysqlurl string) {
	Db_b2b = initMysql(mysqlurl)
}

func initMysql(mysqlurl string) *sql.DB {

	if ok, err := regexp.MatchString("^mysql://.*:.*@.*/.*$", mysqlurl); ok == false || err != nil {
		logging.Error("mysql config syntax err:mysql_zone,%s,shutdown", mysqlurl)
		panic("InitMysql conf error")
		return nil
	}
	mysqlurl = strings.Replace(mysqlurl, "mysql://", "", 1)
	db, err := sql.Open("mysql", mysqlurl)
	if err != nil {
		logging.Error("InitMysql failed mysqlurl=" + mysqlurl + ",err=" + err.Error())
		panic("InitMysql failed mysqlurl=" + mysqlurl)
		return nil
	} else {
		logging.Info("mysql conn ok:%s", mysqlurl)
	}
	_, err2 := db.Begin()
	if err2 != nil {
		logging.Error("begin transaction failed mysqlurl=" + mysqlurl + ",err=" + err2.Error())
		panic("begin transaction failed mysqlurl=" + mysqlurl)
		return nil
	}
	return db
}

func InitCouchbase(url string) {
	var err error
	myCluster, _ := gocb.Connect(url)

	Appliance_base_bucket, err = myCluster.OpenBucket("b2b_appliance_base", "")
	if err != nil {
		logging.Error("util.InitCouchbase init Appliance_base_bucket fail, url:%s, err:%s", url, err.Error())
		panic("util.InitCouchbase b2b_appliance_base failed")
	} else {
		logging.Info("util.InitCouchbase Appliance_base_bucket ok, url:%s", url)
	}
}

//增加家电基础信息
func AddApplianceBase(applianceId uint64, info map[string]interface{}) (ret int) {
	query := gocb.NewN1qlQuery("INSERT INTO `b2b_appliance_base` (KEY, VALUE) VALUES ($1,$2)")
	query.AdHoc(false)

	key := fmt.Sprintf("%s%d", appliance_base_info_prefix, applianceId)
	para := []interface{}{key, info}

	_, err := Appliance_base_bucket.ExecuteN1qlQuery(query, para)
	if err != nil {
		logging.Error("AddApplianceBase ExecuteN1qlQuery failed, err=%s, para[key=%s, value=%+v]",
			err.Error(), key, info)
		return -1
	}

	return 0
}

//根据appliance_code查询索引id
func queryApplianceIdFromCB(applianceCode uint64) (ret int, applianceId uint64) {
	query := gocb.NewN1qlQuery("SELECT id FROM `b2b_appliance_base` WHERE appliance_code=$1 and id is not null and id is not missing")
	query.AdHoc(false)

	para := []interface{}{applianceCode}

	result, err := Appliance_base_bucket.ExecuteN1qlQuery(query, para)
	if err != nil {
		logging.Error("queryApplianceIdFromCB ExecuteN1qlQuery failed, err=%s, para[applianceCode=%d]",
			err.Error(), applianceCode)
		return -1, 0
	}

	var value map[string]uint64
	err = result.One(&value)
	if err != nil {
		if err == gocb.ErrNoResults {
			logging.Error("queryApplianceIdFromCB no result, err=%s, para[applianceCode=%d]",
				err.Error(), applianceCode)
			return -2, 0
		}

		logging.Error("queryApplianceIdFromCB error, err=%s, para[applianceCode=%d]",
			err.Error(), applianceCode)
		return -3, 0
	}

	applianceId = value["id"]
	logging.Debug("queryApplianceIdFromCB ok, applianceId=%d, para[applianceCode=%d]",
		applianceId, applianceCode)

	return 0, applianceId
}

//根据appliance_code查询家电基础信息
func QueryApplianceBaseInfosFromMysql(applianceCodes []interface{}) (ret int, applianceBaseInfos []map[string]interface{}) {
	cnt := len(applianceCodes)
	if applianceCodes == nil || cnt == 0 {
		return -100, nil
	}

	var buffer bytes.Buffer
	buffer.WriteString("select * from t_ms_applian where")

	cnt = cnt - 1
	for i, _ := range applianceCodes {
		if i < cnt {
			buffer.WriteString(" appliance_code=? or")
		} else {
			buffer.WriteString(" appliance_code=?")
		}
	}
	// query smart db for msmart
	sqlstr := buffer.String()
	rows, err := Db_msmart.Query(sqlstr, applianceCodes...)
	if err != nil {
		logging.Error("QueryApplianceBaseInfosFromMysql use Db_msmart, Query err: %s, sqlstr=%s, applianceCodes=%#v",
			err.Error(), sqlstr, applianceCodes)
		return -1, nil
	}

	// Get column names
	columns, err := rows.Columns()
	if err != nil {
		logging.Error("QueryApplianceBaseInfosFromMysql use Db_msmart, Columns err: %s, sqlstr=%s, applianceCodes=%#v",
			err.Error(), sqlstr, applianceCodes)
		return -2, nil
	}

	// Make a slice for the values
	values := make([]sql.RawBytes, len(columns))

	// rows.Scan wants '[]interface{}' as an argument, so we must copy the
	// references into such a slice
	// See http://code.google.com/p/go-wiki/wiki/InterfaceSlice for details
	scanArgs := make([]interface{}, len(values))
	for i := range values {
		scanArgs[i] = &values[i]
	}

	applianceBaseInfos = make([]map[string]interface{}, 0)

	// Fetch rows
	for rows.Next() {
		applianceBaseInfo := make(map[string]interface{})

		// get RawBytes from data
		err = rows.Scan(scanArgs...)
		if err != nil {
			logging.Error("QueryApplianceBaseInfosFromMysql use Db_msmart, Scan err: %s, sqlstr=%s, applianceCodes=%#v",
				err.Error(), sqlstr, applianceCodes)
			return -3, nil
		}

		// Now convert the data into map.
		for i, col := range values {
			column := columns[i]
			// Here we can check if the value is nil (NULL value)
			if col == nil {
				applianceBaseInfo[column] = nil
			} else {
				if column == "id" {
					if id, err := strconv.ParseUint(string(col), 10, 64); err != nil {
						logging.Error("QueryApplianceBaseInfosFromMysql use Db_msmart, ParseUint err: %s, sqlstr=%s, applianceCodes=%#v, id=%s",
							err.Error(), sqlstr, applianceCodes, string(col))
						return -4, nil
					} else {
						applianceBaseInfo[column] = id
					}
				} else if column == "appliance_code" {
					if appliance_code, err := strconv.ParseUint(string(col), 10, 64); err != nil {
						logging.Error("QueryApplianceBaseInfosFromMysql use Db_msmart, ParseUint err: %s, sqlstr=%s, applianceCodes=%#v, appliance_code=%s",
							err.Error(), sqlstr, applianceCodes, string(col))
						return -5, nil
					} else {
						applianceBaseInfo[column] = appliance_code
					}
				} else if column == "active_status" {
					if active_status, err := strconv.ParseUint(string(col), 10, 32); err != nil {
						logging.Error("QueryApplianceBaseInfosFromMysql use Db_msmart, ParseUint err: %s, sqlstr=%s, applianceCodes=%#v, active_status=%s",
							err.Error(), sqlstr, applianceCodes, string(col))
						return -6, nil
					} else {
						applianceBaseInfo[column] = active_status
					}
				} else {
					applianceBaseInfo[column] = string(col)
				}
			}
		}
		logging.Debug("QueryApplianceBaseInfosFromMysql use Db_msmart, applianceBaseInfo=%#v", applianceBaseInfo)
		applianceBaseInfos = append(applianceBaseInfos, applianceBaseInfo)
	}

	if err = rows.Err(); err != nil {
		logging.Error("QueryApplianceBaseInfosFromMysql use Db_msmart, rows.Err: %s, sqlstr=%s, applianceCodes=%#v",
			err.Error(), sqlstr, applianceCodes)
		return -7, nil
	}

	if len(applianceBaseInfos) == 0 {
		return -8, nil
	}

	logging.Debug("QueryApplianceBaseInfosFromMysql use Db_msmart, query ok, %s (%#v) (%#v)", sqlstr, applianceCodes, applianceBaseInfos)
	return
}

func queryApplianceId(applianceCode string) (ret int, applianceId uint64, applianceBaseInfo map[string]interface{}) {
	applianceCodeInt, err := strconv.ParseUint(applianceCode, 10, 64)
	applianceCodeStr := fmt.Sprintf("%d", applianceCodeInt)
	if err != nil || applianceCodeStr != applianceCode {
		logging.Error("queryApplianceId applianceCode format error, strconv.ParseUint.err=%v, applianceCode=%s, applianceCodeInt=%d",
			err, applianceCode, applianceCodeInt)
		return -2, 0, nil
	}

	ret, applianceId = queryApplianceIdFromCB(applianceCodeInt)
	if ret < 0 && ret != -2 {
		logging.Error("queryApplianceId queryApplianceIdFromCB error, ret=%d, applianceCodeInt=%d",
			ret, applianceCodeInt)
		return -3, 0, nil
	} else if ret == 0 {
		logging.Debug("queryApplianceId queryApplianceIdFromCB ok, applianceCodeInt=%d, applianceId=%d",
			applianceCodeInt, applianceId)
		return 0, applianceId, nil
	}

	applianceCodes := []interface{}{applianceCodeInt}
	ret, applianceBaseInfos := QueryApplianceBaseInfosFromMysql(applianceCodes)
	if ret == -8 {
		logging.Error("queryApplianceId QueryApplianceBaseInfosFromMysql error, no row selected, ret=%d, applianceCodes=%#v",
			ret, applianceCodes)
		return -1, 0, nil
	} else if ret < 0 {
		logging.Error("queryApplianceId QueryApplianceBaseInfosFromMysql error, db error, ret=%d, applianceCodes=%#v",
			ret, applianceCodes)
		return -4, 0, nil
	}

	applianceBaseInfo = applianceBaseInfos[0]
	applianceId = applianceBaseInfo["id"].(uint64)
	logging.Debug("queryApplianceId QueryApplianceBaseInfosFromMysql ok, applianceCodes=%#v, applianceId=%d, applianceBaseInfo=%#v",
		applianceCodes, applianceId, applianceBaseInfo)

	return 0, applianceId, applianceBaseInfo
}

//查询用户角色
func queryUserRoleTag(userid string, gatewayId uint64) (ret, roleTag int) {
	// query packages db for b2b
	sqlstr := "select role_tag from t_ms_gw_appliance_user where user_id=? and appliance_id=?"
	row := Db_b2b.QueryRow(sqlstr, userid, gatewayId)

	err := row.Scan(&roleTag)
	if err != nil {
		if err.Error() == sql.ErrNoRows.Error() {
			logging.Error("queryUserRoleTag use Db_b2b, db err: %s, sqlstr=%s, userid=%s, gatewayId=%d",
				err.Error(), sqlstr, userid, gatewayId)
			return -1, -1
		}

		logging.Error("queryUserRoleTag use Db_b2b, db err: %s, sqlstr=%s, userid=%s, gatewayId=%d",
			err.Error(), sqlstr, userid, gatewayId)
		return -2, -1
	}

	logging.Debug("queryUserRoleTag use Db_b2b, query ok, %s (%s, %d) (%d)", sqlstr, gatewayId, roleTag)
	return
}

func queryMasterUserIdByGatewayId(gatewayId uint64) (ret int, userId int64) {
	// query packages db for b2b
	sqlstr := "select user_id from t_ms_gw_appliance_user where appliance_id=? and role_tag=0"
	row := Db_b2b.QueryRow(sqlstr, gatewayId)

	err := row.Scan(&userId)
	if err != nil {
		if err.Error() == sql.ErrNoRows.Error() {
			logging.Error("queryMasterUserIdByGatewayId use Db_b2b, db err: %s, sqlstr=%s, gatewayId=%d",
				err.Error(), sqlstr, gatewayId)
			return -1, -1
		}

		logging.Error("queryMasterUserIdByGatewayId use Db_b2b, db err: %s, sqlstr=%s, gatewayId=%d",
			err.Error(), sqlstr, gatewayId)
		return -2, -1
	}

	if userId < 0 {
		logging.Error("queryMasterUserIdByGatewayId use Db_b2b, db err: userId(%d) < 0, sqlstr=%s, gatewayId=%d",
			userId, sqlstr, gatewayId)
		return -3, -1
	}

	logging.Debug("queryMasterUserIdByGatewayId use Db_b2b, query ok, %s (%d) (%d)", sqlstr, gatewayId, userId)
	return
}

//查询网关家庭id
func queryHouseId(gatewayId uint64) (ret int, houseId uint64) {
	// query packages db for b2b
	sqlstr := "select id from t_ms_gw_house where appliance_id=?"
	row := Db_b2b.QueryRow(sqlstr, gatewayId)

	err := row.Scan(&houseId)
	if err != nil {
		if err.Error() == sql.ErrNoRows.Error() {
			logging.Error("queryHouseId use Db_b2b, db err: %s, sqlstr=%s, gatewayId=%d",
				err.Error(), sqlstr, gatewayId)
			return -1, 0
		}

		logging.Error("queryHouseId use Db_b2b, db err: %s, sqlstr=%s, gatewayId=%d",
			err.Error(), sqlstr, gatewayId)
		return -2, 0
	}

	logging.Debug("queryHouseId use Db_b2b, query ok, %s (%d) (%d)", sqlstr, gatewayId, houseId)
	return
}

//判断网关是否属于用户，返回用户角色
func CheckUserGateway(userid, gatewayid string) int32 {
	ret, gatewayId, applianceBaseInfo := queryApplianceId(gatewayid)
	if ret == -1 {
		logging.Error("CheckUserGateway queryApplianceId error, ret=%d, gatewayid=%s",
			ret, gatewayid)
		return MSMART_USER_NOT_OWN_GATEWAY
	} else if ret < 0 {
		logging.Error("CheckUserGateway queryApplianceId error, ret=%d, gatewayid=%s",
			ret, gatewayid)
		return MSMART_DB_ERROR
	}

	ret, role_tag := queryUserRoleTag(userid, gatewayId)
	if ret == -1 {
		logging.Error("CheckUserGateway queryUserRoleTag error, ret=%d, userid=%s, gatewayId=%d",
			ret, userid, gatewayId)
		return MSMART_USER_NOT_OWN_GATEWAY
	} else if ret < 0 {
		logging.Error("CheckUserGateway queryUserRoleTag error, ret=%d, userid=%s, gatewayId=%d",
			ret, userid, gatewayId)
		return MSMART_DB_ERROR
	}

	f := func() {
		if applianceBaseInfo != nil {
			if ret := AddApplianceBase(gatewayId, applianceBaseInfo); ret != 0 {
				logging.Error("CheckUserGateway AddApplianceBase error, ret=%d, applianceId=%d, applianceBaseInfo=%#v",
					ret, gatewayId, applianceBaseInfo)
			} else {
				logging.Debug("CheckUserGateway util.AddApplianceBase ok, applianceId=%d, applianceBaseInfo=%#v",
					gatewayId, applianceBaseInfo)
			}
		}
	}

	if role_tag == 0 {
		logging.Debug("CheckUserGateway: user is master, userid=%s, gatewayid=%s(%d), role_tag=%d",
			userid, gatewayid, gatewayId, role_tag)
		go f()
		return MSMART_USER_IS_MASTER
	} else if role_tag == 1 {
		logging.Debug("CheckUserGateway: user is shared user, userid=%s, gatewayid=%s(%d), role_tag=%d",
			userid, gatewayid, gatewayId, role_tag)
		go f()
		return MSMART_USER_IS_SHARED_USER
	} else {
		logging.Error("CheckUserGateway: user role is illegal, userid=%s, gatewayid=%s(%d), role_tag=%d",
			userid, gatewayid, gatewayId, role_tag)
		return MSMART_USER_ROLE_IS_ILLEGAL
	}
}

//判断网关是否被用户绑定，返回绑定状态
func CheckGatewayIfBoundByUser(gatewayid string) int32 {
	ret, gatewayId, applianceBaseInfo := queryApplianceId(gatewayid)
	if ret == -1 {
		logging.Error("CheckGatewayIfBoundByUser queryApplianceId error, ret=%d, gatewayid=%s",
			ret, gatewayid)
		return MSMART_GATEWAY_IS_NOT_BOUND_BY_USER
	} else if ret < 0 {
		logging.Error("CheckGatewayIfBoundByUser queryApplianceId error, ret=%d, gatewayid=%s",
			ret, gatewayid)
		return MSMART_DB_ERROR
	}

	ret, user_id := queryMasterUserIdByGatewayId(gatewayId)
	if ret == -1 {
		logging.Error("CheckGatewayIfBoundByUser queryMasterUserIdByGatewayId error, ret=%d, gatewayId=%d",
			ret, gatewayId)
		return MSMART_GATEWAY_IS_NOT_BOUND_BY_USER
	} else if ret < 0 {
		logging.Error("CheckGatewayIfBoundByUser queryMasterUserIdByGatewayId error, ret=%d, gatewayId=%d",
			ret, gatewayId)
		return MSMART_DB_ERROR
	}

	f := func() {
		if applianceBaseInfo != nil {
			if ret := AddApplianceBase(gatewayId, applianceBaseInfo); ret != 0 {
				logging.Error("CheckGatewayIfBoundByUser AddApplianceBase error, ret=%d, applianceId=%d, applianceBaseInfo=%#v",
					ret, gatewayId, applianceBaseInfo)
			} else {
				logging.Debug("CheckGatewayIfBoundByUser util.AddApplianceBase ok, applianceId=%d, applianceBaseInfo=%#v",
					gatewayId, applianceBaseInfo)
			}
		}
	}

	go f()

	logging.Debug("CheckGatewayIfBoundByUser: gateway is bound by user, gatewayid=%s, user_id=%d",
		gatewayid, user_id)
	return MSMART_GATEWAY_IS_BOUND_BY_USER
}

func GetHouseIdByGatewayId(gatewayid string) (ret int, houseId uint64) {
	retInt, gatewayId, applianceBaseInfo := queryApplianceId(gatewayid)
	if retInt == -1 {
		logging.Error("GetHouseIdByGatewayId queryApplianceId error, retInt=%d, gatewayid=%s",
			retInt, gatewayid)
		return MSMART_USER_NOT_OWN_GATEWAY, 0
	} else if retInt < 0 {
		logging.Error("GetHouseIdByGatewayId queryApplianceId error, retInt=%d, gatewayid=%s",
			retInt, gatewayid)
		return MSMART_DB_ERROR, 0
	}

	retInt, houseId = queryHouseId(gatewayId)
	if retInt == -1 {
		logging.Error("GetHouseIdByGatewayId queryHouseId error, retInt=%d, gatewayId=%d",
			retInt, gatewayId)
		return MSMART_USER_NOT_OWN_GATEWAY, 0
	} else if retInt < 0 {
		logging.Error("GetHouseIdByGatewayId queryHouseId error, retInt=%d, gatewayId=%d",
			retInt, gatewayId)
		return MSMART_DB_ERROR, 0
	}

	f := func() {
		if applianceBaseInfo != nil {
			if ret := AddApplianceBase(gatewayId, applianceBaseInfo); ret != 0 {
				logging.Error("GetHouseIdByGatewayId AddApplianceBase error, ret=%d, applianceId=%d, applianceBaseInfo=%#v",
					ret, gatewayId, applianceBaseInfo)
			} else {
				logging.Debug("GetHouseIdByGatewayId util.AddApplianceBase ok, applianceId=%d, applianceBaseInfo=%#v",
					gatewayId, applianceBaseInfo)
			}
		}
	}

	go f()

	return 0, houseId
}

//判断设备是否属于用户
func CheckUserDevice(userid, deviceid string) bool {
	return true
}

//查询网关家庭信息
func queryGatewayHouseInfo(gatewayId uint64) (ret int, houseId uint64, userId int64) {
	// query packages db for b2b
	var buffer bytes.Buffer
	buffer.WriteString("select a.id, a.user_id from t_ms_gw_house a, t_ms_gw_appliance_user b")
	buffer.WriteString(" where a.appliance_id=? and a.appliance_id=b.appliance_id")
	buffer.WriteString(" and a.user_id=b.user_id and b.role_tag=0")
	sqlstr := buffer.String()
	row := Db_b2b.QueryRow(sqlstr, gatewayId)

	err := row.Scan(&houseId, &userId)
	if err != nil {
		if err.Error() == sql.ErrNoRows.Error() {
			ret = -1
		} else {
			ret = -2
		}

		logging.Error("queryGatewayHouseInfo use Db_b2b, db err: %s, sqlstr=%s, gatewayId=%d",
			err.Error(), sqlstr, gatewayId)
		return ret, 0, -1
	}

	logging.Debug("queryGatewayHouseInfo use Db_b2b, query ok, %s (%d) (%d, %d)",
		sqlstr, gatewayId, houseId, userId)
	return
}

//根据用户id获取用户手机号
func queryMobileByUserId(userId int64) (ret int, mobile string) {
	// query smart db for msmart
	sqlstr := "select mobile from t_ms_user where id=?"
	row := Db_msmart.QueryRow(sqlstr, userId)

	err := row.Scan(&mobile)
	if err != nil {
		if err.Error() == sql.ErrNoRows.Error() {
			ret = -1
		} else {
			ret = -2
		}

		logging.Error("queryMobileByUserId use Db_msmart, db err: %s, sqlstr=%s, userId=%d",
			err.Error(), sqlstr, userId)
		return ret, ""
	}

	logging.Debug("queryMobileByUserId use Db_msmart, query ok, %s (%d) (%s)", sqlstr, userId, mobile)
	return
}

//获取网关家庭信息
func GetGatewayHouseInfo(gatewayid string) (ret int, gatewayHouseInfo *GatewayHouseInfo) {
	ret, gatewayId, applianceBaseInfo := queryApplianceId(gatewayid)
	if ret == -1 {
		logging.Error("GetGatewayHouseInfo queryApplianceId gateway appliance info not exists, ret=%d, gatewayid=%s",
			ret, gatewayid)
		return -1, nil
	} else if ret < 0 {
		logging.Error("GetGatewayHouseInfo queryApplianceId db error, ret=%d, gatewayid=%s",
			ret, gatewayid)
		return -2, nil
	}

	ret, houseId, userId := queryGatewayHouseInfo(gatewayId)
	if ret == -1 {
		logging.Error("GetGatewayHouseInfo queryGatewayHouseInfo gateway not bound by user, ret=%d, gatewayId=%d",
			ret, gatewayId)
		return -3, nil
	} else if ret < 0 {
		logging.Error("GetGatewayHouseInfo queryGatewayHouseInfo db error, ret=%d, gatewayId=%d",
			ret, gatewayId)
		return -4, nil
	}

	ret, mobile := queryMobileByUserId(userId)
	if ret == -1 {
		logging.Error("GetGatewayHouseInfo queryMobileByUserId user not exists, ret=%d, userId=%d",
			ret, userId)
		return -5, nil
	} else if ret < 0 {
		logging.Error("GetGatewayHouseInfo queryMobileByUserId db error, ret=%d, userId=%d",
			ret, userId)
		return -6, nil
	}

	f := func() {
		if applianceBaseInfo != nil {
			if ret := AddApplianceBase(gatewayId, applianceBaseInfo); ret != 0 {
				logging.Error("GetGatewayHouseInfo AddApplianceBase error, ret=%d, applianceId=%d, applianceBaseInfo=%#v",
					ret, gatewayId, applianceBaseInfo)
			} else {
				logging.Debug("GetGatewayHouseInfo util.AddApplianceBase ok, applianceId=%d, applianceBaseInfo=%#v",
					gatewayId, applianceBaseInfo)
			}
		}
	}

	go f()

	gatewayHouseInfo = &GatewayHouseInfo{
		HouseId:      houseId,
		MasterUserId: userId,
		Mobile:       mobile,
	}
	logging.Debug("GetGatewayHouseInfo: gateway is bound by user, gatewayid=%s, gatewayHouseInfo=%+v",
		gatewayid, gatewayHouseInfo)
	return 0, gatewayHouseInfo
}
